# FROM maven:3.8.5-openjdk-17-slim AS builder
#FROM maven:3.5-jdk-8-alpine AS builder

# Copy local code to the container image.
# WORKDIR /app
# COPY pom.xml .
# COPY src ./src

# Build a release artifact.
# RUN mvn package -DskipTests

# Run the web service on container startup.
# CMD ["java","-jar","/app/target/user-center-0.0.1-SNAPSHOT.jar","--spring.profiles.active=prod"]


# 使用包含 Maven 和 Java 17 的基础镜像
FROM maven:3.8.5-openjdk-17-slim AS builder

# 设置工作目录
WORKDIR /app

# 复制 Maven 配置文件到镜像中
COPY settings.xml /root/.m2/settings.xml

# 复制项目的 pom.xml 和 src 目录到工作目录
COPY pom.xml .
COPY src ./src

# 构建项目，跳过测试
RUN mvn package -DskipTests

# 第二阶段：创建运行环境
FROM openjdk:17-jdk-slim

# 设置工作目录
WORKDIR /app

# 从第一阶段复制生成的 JAR 包到运行环境
COPY --from=builder /app/target/user-center-0.0.1-SNAPSHOT.jar /app/target/user-center-backend-0.0.1-SNAPSHOT.jar

# 运行容器时启动服务
CMD ["java", "-jar", "/app/target/user-center-backend-0.0.1-SNAPSHOT.jar", "--spring.profiles.active=prod"]
